try{
if (arguments.length != 2)
  throw "usage: fichier n"
var n = +arguments[1]
if (isNaN(n))
  throw "n is not a number";
var samples = readFile(arguments[0]);
if (!samples)
  throw "file "+arguments[0]+" is empty";

load(
  "array.js",
  "functionnal.js",
  "number.js",
  "math.js"
);

samples = Array.transform(samples.replace(/^[0-9]+\n+|\n+$/g, '').split('\n'), Number);
var sample = samples.length;
var isTrue = logical('<=', 960);

var p = samples.count(isTrue) / sample;
var vp = p*(1-p)
print("Population: "+arguments[0])
print("Nombre d'individus: "+sample)
print("Proportion p: "+p);
print("Ecart-type s: "+Math.sqrt(vp))
print("Echantillions de taille: "+n)

var cursors = [i for (i in range(0, n))];
var length = cursors.length;
var index = length - 1;
var m = 0;
var combination = 0;
var v = 0;
while (1)
{
  var tmp = cursors.count(function(v){return isTrue(samples[v])});
  m += tmp
  v += tmp * tmp
  ++combination;
  if (++cursors[index] === sample)
  {
	if (cursors[0] === sample-n)
	  break;
	while (++cursors[index-1] === cursors[index]-1)
	  --index;
	for (var i = index; i < length; ++i)
	  cursors[i] = cursors[i-1] + 1;
	index = length - 1;
  }
}
var den = combination * n
m /= den
v = v/(den * n) - m*m;
print("Nombre d'echantillons: "+combination)
print("Moyenne: "+m)

m = Array.sum(samples) / sample;
print("Moyenne de la population: "+m)
print("Ecart-type: "+Math.sqrt(v))
print("Ecart-type calculé d'après s': "+Math.sqrt(vp*(sample-n)/((sample-1)*n)))

}
catch(e)
{print(e);}